
int printk(const char* fmt, ...)
{
     int escape = 0; 		/* % escape flag */
     char* stack_ptr = (char*)&fmt + 4;
     int index = 0;
     int counter = 0; 		/* chars printed */
     
     while(fmt[index])
     {
	  if(escape)
	  {
	       switch (fmt[index])
	       {
	       case '%':
		    putc('%');
		    break;
	       case 'c':
		    putc(*stack_ptr);
		    stack_ptr += 4;
		    break;
	       case 's':
		    puts(*(char**)stack_ptr);			       
		    stack_ptr += 4;			       
		    break;
	       case 'x':
		    disp_hex(*(int*)stack_ptr);
		    stack_ptr += 4;		    
		    break;
	       case 'd':
		    disp_int(*(int*)stack_ptr);
		    stack_ptr += 4;		    
		    break;
	       default:
		    puts("\nUnknown escape pair: %");
		    putc(fmt[index]);
	       }
	       escape = 0;
	  }
	  else
	  {
	       if(fmt[index] == '%')
	       {
		    escape = 1;
	       }
	       else
	       {
		    putc(fmt[index]);
	       }
	  }
	  index++;
     }

     return counter;
}

